﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQuarters.WebQuarters.Core;

namespace OpenQuarters.WebQuarters.Tests.Model
{
    [TestFixture]
    public class CMSPageTests : TestBase
    {
        [Test]
        [Explicit]
        public void CreateDraftPage()
        {
            CMSPage page = new CMSPage();
            page.EnsureDraftVersion("DraftTest");
            page = page.Save();

            Assert.IsNotEmpty(page.Urls);

        }


        [Test]
        [Explicit]
        public void TestDatePArse()
        {
            string toparse = "2009-08-14, 2009-08-15, 2009-08-16, 2009-08-17, 2009-08-18, 2009-08-18, 2009-08-19, 2009-08-20, 2009-08-21, 2009-08-22, 2009-08-23";
            string parsed = "";

            int previousday = -1;

            foreach (string thedate in toparse.Split(','))
            {
                
                if (thedate.Trim() != "")
                {
                    if (previousday + 1 == Convert.ToDateTime(thedate).Day && parsed.Substring(parsed.Length - 1) != "-")
                    {
                        parsed = parsed.Substring(0, parsed.Length-1) + "-";
                    }
                    else if (previousday + 1 == Convert.ToDateTime(thedate).Day && parsed.Substring(parsed.Length - 1) == "-" && parsed.Length != 0)
                    {
                    }
                    else
                    {
                        if (parsed.Length != 0 && parsed.Substring(parsed.Length - 1) == "-")
                            parsed += previousday + "," + Convert.ToDateTime(thedate).Day + ",";
                        else
                            parsed += Convert.ToDateTime(thedate).Day + ",";
                    }

                    previousday = Convert.ToDateTime(thedate).Day;
                }
            }

            if (parsed.Substring(parsed.Length - 1) == "-")
                parsed += previousday;

            string result; 
            if (parsed.Substring(parsed.Length - 1) == ",")
                result = parsed.Substring(0, parsed.Length - 2) + " August 2009";
            else
                result = parsed + " August 2009";
        }
    }
}
